var assert = require('assert');
var should = require('should');
var util = require('util');
var _ = require('lodash');
var roleModel = require('../../app/models/roleModel');
var config = require('../config');
var roleSchema = require('../../app/schemas/roleSchema');
var mongoConnector = require('../../app/libs/mongodb/mongoConnector');
var Role = mongoConnector().model('Role');

suite('测试roleModel', function () {
    var role_model;
    setup(function (done) {
        roleModel.getByRoleId(config.role_id, function (err, model) {
            if (!!model) {
                role_model = model;
                return done();
            }

            Role.create({
                uid: config.uid,
                channel_id: 'guest_10000',
                role_id: config.role_id,
                name: 'test1',
                job_type: 1
            }, function (err, model) {
                role_model = model;
                done();
            });
        });
    });

    // suite('getRoleList', function (done) {
    //     test('获取角色列表', function (done) {
    //         roleModel.getByRoleId('***', function (err, model) {
    //             done();
    //         });
    //     });
    // });

    suite('getRoleList', function () {
        test('获取角色列表', function (done) {
            roleModel.getRoleList(config.role_id, function (err, role_list) {
                done();
            });
        });
    });

    suite('getByRoleId', function () {
        test('获取角色', function (done) {
            roleModel.getByRoleId(config.role_id, function (err, role_model) {
                done();
            });
        });
    });

    suite('createRole', function () {
        test('创建角色', function (done) {
            roleModel.createRole(config.uid, 'guest_10000', config.role_id, 'test', function (err, model) {
                Role.remove({
                    name: 'test'
                }, done);
            });
        });
    });

    suite('getName', function () {
        test('获取名字', function () {
            role_model.getName();
        });
    });

    suite('setName', function () {
        test('修改名字', function (done) {
            role_model.setName('test2');
            role_model.save(function (err) {
                done();
            });
        });
    });

    suite('addGold', function () {
        test('添加金币', function (done) {
            role_model.addGold(1000);
            role_model.save(function (err) {
                assert.equal(null, err);
                done();
            });
        });
    });

    suite('subGold', function () {
        test('扣除金币', function () {
            role_model.gold = 0;
            role_model.addGold(1000);
            var result = role_model.subGold(1000);
            role_model.getGold().should.equal(0);
            result.should.eql(true);
        });
    });

    suite('subGold', function () {
        test('扣除金币失败', function () {
            var result = role_model.subGold(100000000);
            result.should.eql(false);
        });
    });

    suite('addFood', function () {
        test('添加粮食成功', function () {
            role_model.addFood(1000);
        });
    });

    suite('subFood', function () {
        test('扣除粮食成功', function () {
            role_model.addFood(1000);
            var result = role_model.subFood(1000);
            result.should.eql(true);
        });
    });

    suite('subFood', function () {
        test('扣除粮食失败', function () {
            role_model.subFood(role_model.getFood());
            var result = role_model.subFood(1000);
            result.should.eql(false);
        });
    });

    suite('subDiamond', function () {
        test('扣除钻石失败', function () {
            role_model.addDiamond(1000);
            var result = role_model.subDiamond(1000);
            result.should.eql(true);
        });
    });

    suite('subDiamond', function () {
        test('扣除钻石失败', function () {
            role_model.addDiamond(1000);
            var result = role_model.subDiamond(1);
            role_model.save();
            result.should.eql(true);
        });
    });

    suite('addWorker', function () {
        test('添加工人成功', function () {
            role_model.addWorker();
        });
    });

    suite('getRoleByNobleListNotInProtect', function () {
        test('根据官阶列表获取角色', function (done) {
            roleModel.getRoleByNobleListNotInProtect(config.role_id, [1, 2, 3, 4, 5], function (err, data) {
                done();
            });
        });
    });

    suite('login', function () {
        test('登录1', function (done) {
            roleModel.login(config.role_id, done);
        });

        // test('登录2', function (done) {
        //     roleModel.login('***', done);
        // });
    });

    suite('logout', function () {
        test('登出1', function (done) {
            roleModel.logout(config.role_id, done);
        });

        // test('登出2', function (done) {
        //     roleModel.logout('***', done);
        // });
    });

    suite('getLevelList', function () {
        test('获取每个等级的区间的人', function (done) {
            roleModel.getLevelList(1, 100, done);
        });
    });

    suite('getRoleInfoByRoleId', function () {
        test('获取角色ID查询角色信息', function (done) {
            roleModel.getRoleInfoByRoleId(config.role_id, done);
        });
    });

    suite('getRoleInfoByName', function () {
        test('根据角色名获取角色信息', function (done) {
            roleModel.getRoleInfoByName('test', done);
        });
    });

    suite('getRoleLv', function () {
        test('获取角色等级', function (done) {
            roleModel.getRoleLv('***', done);
        });
    });

    suite('getRoleByNameKeyWord', function () {
        test('获取角色', function (done) {
            roleModel.getRoleByNameKeyWord('t', function (err, res) {
                done();
            });
        });
    });

    suite('getAllRoleList', function () {
        test('增加已购买体力次数', function (done) {
            this.timeout(999999);
            roleModel.getAllRoleList(function (err, result) {
                // console.log(result);
                done();
            });
        });
    });

    suite('addBuySpNum', function () {
        test('增加已购买体力次数', function (done) {
            role_model.addBuySpNum();
            role_model.save(function (err) {
                done();
            });
        });
    });

    suite('getBuySpNum', function () {
        test('获取已购买体力次数', function () {
            role_model.getBuySpNum();
        });
    });

    suite('addEnergy', function () {
        test('获取已购买体力次数', function () {
            role_model.addEnergy(20);
            role_model.save();
        });
    });
});
